<?php
namespace app\index\controller;

use think\Controller;
use think\Session;
use app\index\model\Menu;
use app\index\model\rm;

class Index extends Controller
{
    public function index(){
        return $this->fetch();
    }

    public function system(){
        return $this->fetch();
    }

    public function head(){
        $usersession = Session::get('Uname');
        //$usercookie = Cookie::get('Uname');
        if(!$usersession){
            $user = '<span class="log"><a href="login" target="_top">登录</a></span>';
            $this->assign('User',$user);
        }else{
            $user = '<span class="log">'.$usersession.'</span>
            <span class="pt">|</span>       
            <a href="logout" target="_top"><span class="log">退出</span></a>';
            $this->assign('User',$user);
        }
        return $this->fetch();
    }

    public function left(){
        $userstatus = Session::get('Ustatus');
        $hint = '';
        $this->assign('hint',$hint);
        $pmenu = '';
        $this->assign('pmenu',$pmenu);
        if(!isset($userstatus)){
            $hint = 
            '<li>
    	        <a href="login" target="_top">登录后查看列表</a>
            </li>';
            $this->assign('hint',$hint);
        }else{
            $rmmodel = new Menu();
            $pmenu = $rmmodel->List($userstatus);
            // dump($pmenu->toArray());
            // dump($pmenu[0]->cmenu->toArray());
            if(!empty($pmenu)){
                $this->assign('pmenu',$pmenu);
            }
        }
        return $this->fetch();
    }

    public function login(){
        return $this->redirect('login/Login/login');
    }

    public function logout(){
        Session::delete('Uname');
        return $this->redirect('login/Login/login');
    }
}

?>